package com.future.north.service.impl;

import com.future.north.api.UserService;
import com.future.north.manager.UserManager;
import com.future.north.api.model.User;
import com.future.north.utils.ServiceResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class UserServiceImpl implements UserService {
    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private UserManager userManager;

    public ServiceResult<User> getUserById(Long userId) {
        if (Objects.isNull(userId)) {
            return new ServiceResult<>(10001, "用户id不能为空");
        }

        try {
            return new ServiceResult<>(userManager.getUserById(userId));
        } catch (Exception ex) {
            logger.error("UserServiceImpl->getUserById,获取服务数据失败:" + ex.getMessage(), ex);
            return new ServiceResult<>(10001, "获取服务数据失败");
        }
    }
}
